/**
 * PageMarket
 * MainActivity.java
 * com.android.pagemarket.ui.activity.main
 * 
 */
package com.android.pagemarket.ui.activity.main;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;

import com.android.pagemarket.MyApplication;
import com.android.pagemarket.R;
import com.android.pagemarket.business.logic.InitManager;
import com.android.pagemarket.ui.activity.base.TemplateActivity;
import com.android.pagemarket.ui.activity.price.NewPriceActivity;
import com.android.pagemarket.ui.activity.query.TransQueryActivity;
import com.android.pagemarket.ui.activity.schedul.SchedulActivity;
import com.android.pagemarket.ui.widget.FoucsPopWindow;
import com.android.pagemarket.ui.widget.TitleBar;
import com.android.pagemarket.ui.widget.TitleBar.OnTitleClickListener;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-10-29
 * @see : 首页视图
 * @Copyright : copyrights reserved by personal 2007-2012
 **********************************************************/
public class MainActivity extends TemplateActivity implements OnClickListener
{
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);        
        setContentView(R.layout.activity_main);
    }
    
    @Override
    protected void onResume()
    {
        super.onResume();
        if(InitManager.getInstance().isLogin())
        {
            mTitleBar.setRigthText(R.string.tx_logon);
        }else
        {
            mTitleBar.setRigthText(R.string.tx_login);
            if(MyApplication.getContext().isShowTipLogin())
            {
                // 提示登录
//                showFoucsPopWindow();
                ((MainIndexActivity)getParent()).showFoucsPopWindow();
                MyApplication.getContext().resetStartCount();
            }else 
            {
                MyApplication.getContext().addVisitStartCount();
            }
        }
    }
    
    @Override
    public void onBackPressed()
    {
        if( getParent() instanceof MainIndexActivity)
        {
            ((MainIndexActivity)getParent()).onBackPressed();
        }
    }
    
    @Override
    protected void setupTitleBar(TitleBar titleBar)
    {
        titleBar.setTitle(R.string.title_start);
        titleBar.setLeftVisible(false);
        titleBar.setRigthText(R.string.tx_login);
        
        titleBar.setOnTitleClickListener(new OnTitleClickListener()
        {
            @Override
            public void onRightClick()
            {
                LoginActivity.startActivity(MainActivity.this);
            }
        }, false, true);
    }

    @Override
    public void onClick(View v)
    {
        switch(v.getId())
        {
            case R.id.price_lay:
            {
                NewPriceActivity.startActivity(this);
                break;
            }
            case R.id.shedule_lay:
            {
                SchedulActivity.startActivity(this);
                break;
            }
            case R.id.query_lay:
            {
                TransQueryActivity.startActivity(this);
                break;
            }
        }
    }    
    
    void showFoucsPopWindow()
    {
        if(getPopupWin() == null)
        {
            setPopWin( new FoucsPopWindow(getParent()));
        }
        getPopupWin().showAtLocation(getParent().getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);        
    }
}
